<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <div>{{ countCopy }}</div>
        <div><button @click="add">add</button></div>
        <div><button @click="asyncAdd">asyncAdd</button></div>
    </div>

    <script src="https://unpkg.com/vue@next"></script>
    <script src="https://unpkg.com/vuex@4"></script>
    <script>

        const store = Vuex.createStore({
            state(){
                return {
                    count: 0
                }
            },
            mutations: {
                add(state){
                    state.count ++
                }
            },
            actions: {
                add(context){
                   setTimeout(() => {
                        context.commit('add')
                   }, 1000);
                }
            }
        })
        const app = Vue.createApp({
            computed: {
                countCopy(){
                    return this.$store.state.count
                }
            },
            methods: {
                add(){
                    console.log(this)
                    this.$store.commit('add')
                },
                asyncAdd(){
                    this.$store.dispatch('add')
                }
            }
        })
        app.use(store)
        app.mount('#app')
    </script>
</body>
</html>